/*******************************************************************************
 * Copyright (c) 2009 Kevin Bierhoff and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Kevin Bierhoff - initial API and implementation
 *******************************************************************************/
package com.googlecode.twelfdevtools.views;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import com.googlecode.twelfdevtools.TwelfActivator;
import com.googlecode.twelfdevtools.model.IElfFile;
import com.googlecode.twelfdevtools.model.ITwelfConstant;
import com.googlecode.twelfdevtools.model.ITwelfProject;


public class TwelfModelLabelProvider extends LabelProvider implements ILabelProvider {

	@Override
	public Image getImage(Object element) {
		String iconKey = null;
		if (element instanceof ITwelfConstant) {
			ITwelfConstant c = (ITwelfConstant) element;
			if (c.getDeclaration().trim().endsWith("type"))
				iconKey = TwelfActivator.ICON_TWELF_TYPE;
		}
		else if (element instanceof IElfFile)
			iconKey = TwelfActivator.ICON_ELF_FILE;
		else if (element instanceof ITwelfProject)
			iconKey = TwelfActivator.ICON_TWELF_HAT;

		if (iconKey != null)
			return TwelfActivator.getDefault().getImage(iconKey);
		return super.getImage(element);
	}

	@Override
	public String getText(Object element) {
		if (element instanceof ITwelfConstant) {
			ITwelfConstant c = (ITwelfConstant) element;
			return c.getDeclaration().replace("\n", "");
		}
		if (element instanceof IElfFile) {
			IElfFile f = (IElfFile) element;
			return f.getResource().getProjectRelativePath().toPortableString();
		}
		if (element instanceof ITwelfProject) {
			return ((ITwelfProject) element).getResource().getName();
		}
		return super.getText(element);
	}

	
	
}
